package com.cskaoyan.service;

import com.cskaoyan.bean.Comment;
import com.cskaoyan.bean.ListData;
import com.cskaoyan.mapper.CommentMapper;
import com.cskaoyan.utils.DateUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentServiceImpl implements CommentService {
    @Autowired
    CommentMapper commentMapper;
    @Override
    public ListData<Comment> queryList(Integer page, Integer limit, Integer userId, Integer valueId, String sort, String order) {
        PageHelper.startPage(page,limit);
        String valueIdS = null;
        String userIdS = null;
        if (valueId!=null){
            valueIdS = "%"+valueId+"%";
        }
        if (userId!=null){
            userIdS = "%"+userId+"%";
        }
        String sortAndOrder =sort+" "+order;
        List<Comment> commentList =  commentMapper.selectBySortAndOrder(userIdS,valueIdS,sortAndOrder);
        ListData<Comment> commentListData = new ListData();
        PageInfo<Comment> commentPageInfo = new PageInfo<>(commentList);
        commentListData.setTotal( commentPageInfo.getTotal());
        commentListData.setItems(commentList);
        return commentListData;
    }

    @Override
    public void deleteById(Integer id) {
        Comment comment = new Comment();
        comment.setId(id);
        comment.setDeleted(true);
        int update = commentMapper.updateByPrimaryKeySelective(comment);
    }
    // 对确认收货后的商品进行评价
//    @Override
//    public void insertComment(Comment comment) {
//        comment.setAddTime(DateUtils.getCurrentTime());
//        comment.setUpdateTime(DateUtils.getCurrentTime());
//        commentMapper.insertSelective(comment);
//    }

//    @Override
//    public void insertComment(Comment comment) {
//
//        commentMapper.insertSelective(comment);
//    }
}
